import { createRouter, createWebHashHistory } from "vue-router";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      //主页路由
      path: "/",
      name: "index",
      component: () => import("@/layout/index/index.vue"),
      redirect: "home",
      children: [
        {
          path: "home",
          name: "home",
          component: () => import("@/views/home/index.vue"),
        },
        {
          path: "menu",
          name: "menu",
          component: () => import("@/views/menu/index.vue"),
        },
        {
          // 购物车页面路由
          path: "cart",
          name: "cart",
          component: () => import("@/views/cart/index.vue"),
        },
        {
          //用户页面路由
          path: "user",
          name: "user",
          component: () => import("@/views/user/index.vue"),
        },
        {
          path: "search",
          name: "search",
          component: () => import("@/views/search/index.vue"),
        },
        {
          path: "category",
          name: "category",
          component: () => import("@/views/category-view/index.vue"),
        },
        {
          path: "address",
          name: "address",
          component: () => import("@/views/address/index.vue"),
        },
      ],
    },
    //   登录页
    {
      path: "/login",
      name: "login",
      component: () => import("@/layout/login/index.vue"),
    },
    // 详情页
    {
      path: "/details",
      name: "details",
      component: () => import("@/layout/details-page/index.vue"),
    },
    // 生成订单页面
    {
      path: "/order",
      name: "order",
      component: () => import("@/layout/order/index.vue"),
    },
    {
      // 任意路由
      path: "/:path(.*)*",
      name: "any",
      redirect: "/home",
    },
  ],
});

export default router;
